﻿namespace Anley.DomainDrivenDesign.Contract;

/// <summary>
/// 日期时间扩展类
/// </summary>
public static class DateTimeExtension
{
    /// <summary>
    /// 生成时间戳
    /// </summary>
    /// <param name="dateTime"></param>
    public static long GenerateTimestamp(
        this DateTime dateTime)
    {
        var flagTime = new DateTime(1970, 1, 1);
        return (long)(dateTime - flagTime).TotalMilliseconds;
    }

    /// <summary>
    /// 反转时间戳
    /// </summary>
    /// <param name="timestamp"></param>
    public static DateTime ReverseTimestamp(
        this long timestamp)
    {
        var flagTime = new DateTime(1970, 1, 1);
        return flagTime.AddMilliseconds(timestamp);
    }
}